package com.kuang.demo.controller.wx;

import com.kuang.demo.bean.BaseRespVo;
import com.kuang.demo.bean.wx.*;
import com.kuang.demo.service.wx.ShoppingCartService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;



/**
 * @author ACG
 * @date 2020-11-04 16:33
 */
@RestController
@RequestMapping("wx/cart")
public class ShoppingCartController {
@Autowired
    ShoppingCartService shoppingCartService;


    //http://182.92.235.201:8083/wx/cart/goodscount
    @RequestMapping("/goodscount")
    public BaseRespVo goodsCountControl(){
      Integer goodsSum = shoppingCartService.goodsCountControl();
        return BaseRespVo.ok(goodsSum);
    }

    //http://182.92.235.201:8083/wx/cart/add
    @RequestMapping("/add")
    public BaseRespVo addControl(@RequestBody ShoppingCartFastaddBean shoppingFastaddBean){
        int sum = shoppingCartService.addControl(shoppingFastaddBean);
        return BaseRespVo.ok(sum);
    }

    //http://182.92.235.201:8083/wx/cart/index
    @RequestMapping("/index")
    public BaseRespVo indexControl(){
        ShoppingCartIndexData shoppingCartIndexData = shoppingCartService.indexControl();
        return BaseRespVo.ok(shoppingCartIndexData);
    }


    //http://182.92.235.201:8083/wx/cart/checkout?cartId=0&addressId=32&couponId=0&grouponRulesId=36
    //todo
    @RequestMapping("/checkout")
    public BaseRespVo checkoutControl(Integer cartId,Integer addressId,String couponId,String grouponRulesId){
        ShoppingCartCheckoutData shoppingUpdateData= shoppingCartService.checkoutControl(cartId,addressId,couponId,grouponRulesId);
        return BaseRespVo.ok(shoppingUpdateData);
    }

    //http://182.92.235.201:8083/wx/cart/delete
    @RequestMapping("/delete")
    public BaseRespVo deleteControl(@RequestBody ShoppingCartCheckedBean shoppingCartCheckedBean){
        ShoppingCartIndexData shoppingCartIndexData = shoppingCartService.deleteControl(shoppingCartCheckedBean);
        return BaseRespVo.ok(shoppingCartIndexData);
    }

    //http://182.92.235.201:8083/wx/cart/fastadd

    @RequestMapping("/fastadd")
    public BaseRespVo fastaddControl(@RequestBody ShoppingCartFastaddBean fastaddBean){
      Integer integer =  shoppingCartService.fastaddControl(fastaddBean);
        return BaseRespVo.ok(integer);
    }

    //http://182.92.235.201:8083/wx/cart/checked
    @RequestMapping("/checked")
    //isChecked: 1
    //productIds: [54]
    public BaseRespVo checkedControl(@RequestBody ShoppingCartCheckedBean shoppingCartCheckedBean){
        ShoppingCartIndexData shoppingCartIndexData =   shoppingCartService.checkedControl(shoppingCartCheckedBean);
        return BaseRespVo.ok(shoppingCartIndexData);
    }

    //http://182.92.235.201:8083/wx/cart/update
    @RequestMapping("/update")
    public BaseRespVo updateControl(@RequestBody ShoppingCartUpdateGoodsBean shoppingCartUpdateGoodsBean){
        shoppingCartService.updateControl(shoppingCartUpdateGoodsBean);
        return BaseRespVo.ok();
    }

}
